import { Injectable } from '@angular/core';
import {Router} from "@angular/router";
import {UserInfo} from "./energy/api/model/userInfo";

@Injectable({
  providedIn: 'root',
})
export class UserService {
  public static user:UserInfo = null;
  constructor(private router:Router) {

  }

  setUser(user:UserInfo){
    UserService.user = user;
  }

  getUser():UserInfo{
    if(UserService.user==null)
      this.router.navigate(["/auth"]);
    return UserService.user;
  }

  hasLogin():boolean{
    return UserService.user!=null
  }
}
